﻿using Architecture.API.Application.TraceabilityCommand.PackagingMaterialsCommand;
using MediatR;
using Traceability.Domain.Service.PackagingMaterialsServices;
using Traceability.Domain.SupplierDomain;

namespace Architecture.API.Application.TraceabilityCommandHandler.PackagingMaterialsCommandHandler
{
    /// <summary>
    /// 
    /// </summary>
    public class UpdatePackagingMaterialsCommandHandler : IRequestHandler<UpdatePackagingMaterialsCommand, int>
    {
        /// <summary>
        /// 包材服务
        /// </summary>
        protected readonly IPackagingMaterialsService packagingMaterialsService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="packagingMaterialsService">包材服务</param>
        public UpdatePackagingMaterialsCommandHandler(IPackagingMaterialsService packagingMaterialsService)
        {
            this.packagingMaterialsService = packagingMaterialsService;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<int> Handle(UpdatePackagingMaterialsCommand request, CancellationToken cancellationToken)
        {
            return await packagingMaterialsService.UpdatePackagingMaterials(new PackagingMaterials() { PackagingMaterialsId=request.PackagingMaterialsId,PackagingMaterialsProductionBatch=request.PackagingMaterialsProductionBatch,UpdatedBy=request.UpdatedBy,UpdatedDate=DateTime.Now});
        }
    }
}
